/*
 * RecordarContrasenia.java
 *
 * Created on 3 de abril de 2007, 11:50
 */

package despachador.pagina;

import excepciones.AvwException;
import gestores.administracion.GestorUsuario;
import gestores.pagina.GestorCliente;
import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author Administrador
 * @version
 */
public class RecordarContrasenia extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void processRequest(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        String url = "/micrositios/" + (String) request.getAttribute("nomMicro");
        
        String email = "";
        
        // Especificamos que pagina se coloca en cada parte del layout
        request.setAttribute("1", url + "/encabezado.jsp");
        request.setAttribute("2", url + "/destacado.jsp");
        request.setAttribute("3", url + "/buscador.jsp");
        request.setAttribute("4", "/vistas/pagina/menuizq.jsp");
        request.setAttribute("5", url + "/bannerizq.jsp");
        
        if (request.getParameter("email") != null){
            email = String.valueOf(request.getParameter("email"));
            try {
                Boolean ok = GestorCliente.recordarContrasenia(email);
                if(ok){
                    HttpSession session = request.getSession(true);
                    response.sendRedirect("./index?" + (String) session.getAttribute("atributosUrl") + 
                            "_msg_advertencia=Se ha enviado un e-mail a su casilla");
                    return;
                }else{
                    request.setAttribute("6", "/vistas/pagina/recordarContrasenia.jsp");
                }
            } catch (AvwException e) {
                request.setAttribute("error",
                        e.getMessage());
                dispatch(request, response, "/compositor/pagina/error.jsp");
            }
        }else{
            request.setAttribute("6", "/vistas/pagina/recordarContrasenia.jsp");
        }
        
        request.setAttribute("7", "/vistas/pagina/visitados.jsp");
        request.setAttribute("8", "/vistas/pagina/login.jsp");
        request.setAttribute("9", "/vistas/pagina/rss.jsp");
        request.setAttribute("11", "/vistas/pagina/marcas.jsp");
        request.setAttribute("10", url + "/pie.jsp");
        
        dispatch(request, response, "/compositor/pagina/nuevecuerpos.jsp");

    }
    
    public void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }
    
    public void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /**
     * dispatcher method
     */
    protected void dispatch(HttpServletRequest request,
            HttpServletResponse response, String page)
            throws javax.servlet.ServletException,
            java.io.IOException {
        RequestDispatcher dispatcher =
                getServletContext().
                getRequestDispatcher(page);
        dispatcher.forward(request, response);
    }
}
